package xinyu.customer.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import xinyu.customer.R;
import xinyu.customer.base.BaseRecyclerAdapter;
import xinyu.customer.bean.NewsMainTopBean;

/**
 * description ： TODO:类的作用
 * author : SIGHT-WXC
 * email : 391335693@qq.com
 * date : 2020-04-15 19:21
 */
public class NewsMainTopAdapter extends BaseRecyclerAdapter<NewsMainTopBean> {

    public NewsMainTopAdapter(Context context) {
        super(context, NEITHER);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        return new Holder(mInflater.inflate(R.layout.item_news_main_top, parent, false));
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, NewsMainTopBean item, int position) {
        Holder vh = (Holder) holder;
        vh.img.setImageResource(item.getImgUrlId());
        vh.tvName.setText(item.getName());
        vh.tvNum.setText(item.getNum()+"");
        vh.tvNum.setVisibility(item.getNum()==0?View.INVISIBLE:View.VISIBLE);
    }

    private class Holder extends RecyclerView.ViewHolder {
        TextView tvName,tvNum;
        ImageView img;
        Holder(View convertView) {
            super(convertView);
            tvName = convertView.findViewById(R.id.tv_name);
            tvNum = convertView.findViewById(R.id.tv_num);
            img = convertView.findViewById(R.id.img);
        }
    }
}
